import VueRouter from 'vue-router'
import Vue from 'vue'
import Home from "@/components/Home.vue";


Vue.use(VueRouter)

// 解决重复路由的问题。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 解决重复路由的问题。replace
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
    routes:[
        /* redirect 重定向 */
        { path:'/',redirect:'/home'},
        { 
            path:'/home',
            component:Home,
            children:[
                {
                    path:'/',
                    redirect:'news'
                },
                {
                    path: 'goods',
                    component: () => import("@/components/Goods.vue"),
                },
                {
                    path: 'news',
                    component: () => import("@/components/News.vue"),
                }
            ]
        },
        { path: '/about', component: () => import("@/components/About.vue")},
        { path: '/category', component: () => import("@/components/Category.vue")},
        { path: '/user/:func', component: () => import("@/components/User.vue")},
    ],
    mode: "history"
})

export default router;